package com.example.service.impl;

import com.example.service.UserService;
import com.example.repository.UserRepository;
import com.example.component.LoggerComponent;

// 注意：这里没有使用@Service注解，因为我们将在配置类中手动定义Bean
public class UserServiceImpl implements UserService {
    
    private UserRepository userRepository;
    private LoggerComponent logger;
    
    // 通过构造函数注入依赖
    public UserServiceImpl(UserRepository userRepository, LoggerComponent logger) {
        this.userRepository = userRepository;
        this.logger = logger;
        logger.log("UserServiceImpl实例已创建");
    }
    
    @Override
    public void registerUser(String username, String email) {
        logger.log("注册用户: " + username);
        int userId = userRepository.saveUser(username, email);
        logger.log("用户注册成功，ID: " + userId);
    }
    
    @Override
    public String getUserInfo(int userId) {
        logger.log("查询用户信息，ID: " + userId);
        return userRepository.getUserInfo(userId);
    }
    
    @Override
    public int getTotalUsers() {
        return userRepository.getUserCount();
    }
}